use "$LocalData\BartikAnalyticData_2digit.dta", clear

* Set panel variables
xtset geography year

*Generating year-industry-shares for computation for Bartik analytics and SEs
		keep if year>2002  //Restricts to period of analysis
		
		levelsof year, local(y) //Creates a macro list of all years
		
		foreach year in `y' {
			foreach ind_var of varlist c_i_share_2000* {
				qui gen t`year'_`ind_var' = `ind_var' * (year == `year')
				}
			}
	
		qui tab year, gen(year_) //Generates year dummies
		drop year_1
		qui tab geography, gen(geography_) //Generates year dummies
		drop geography_1
		

/******************************************************************************/
/******************************************************************************/
/* Regressions                                                                */
/******************************************************************************/
/******************************************************************************/

local years  (year>2002) & abs(gsmall_dep1)<5 & gSmallFirm1!=.
*local controls ln_pop_2000 unem_2000 urban_2000 lnincome2000 lnbr2000 small_dep_share2000
local controls 	dlngdp unem_change pop_growth annualchange 

gen testconditions = cond(`years',1,0)
bysort geography: egen insample = sum(test)
keep if insample>1

/**********************/
/* Simple Regressions */
/**********************/
noi display "Running simple regressions."

local years  (year>2002) & abs(gsmall_dep1)<5 & gSmallFirm1!=.
*local controls ln_pop_2000 unem_2000 urban_2000 lnincome2000 lnbr2000 small_dep_share2000
local controls 	dlngdp unem_change pop_growth annualchange 

eststo: xtivreg2 gsmall_dep1 year_* (gSmallFirm1 = bartikGS1)  if `years', fe cluster(cluster3)
gen mainsample = e(sample)

local years  mainsample==1


eststo: reg gsmall_dep1 gSmallFirm1 i.year if `years', vce(cluster cluster3)
outreg2 using "$LocalData\Tables\BartikRegTable_1", tex replace ///
	ctitle(SmDepGr) keep(gSmallFirm1 gLargeFirm1 `controls' ) ///
	addtext(REG, OLS, YEAR, NO, COUNTY FE, NO, YRS, 2003-2017)

eststo: reg gsmall_dep1 gSmallFirm1 i.year `controls' if `years', ///
	vce(cluster cluster3)
outreg2 using "$LocalData\Tables\BartikRegTable_1", tex append ///
	ctitle(SmDepGr) keep(gSmallFirm1 `controls' ) ///
	addtext(REG, OLS, YEAR, YES, COUNTY FE, NO, YRS, 2003-2017)

eststo: areg gsmall_dep1 gSmallFirm1 i.year if `years', ///
	vce(cluster cluster3) absorb(geography)
outreg2 using "$LocalData\Tables\BartikRegTable_1", tex append ///
	ctitle(SmDepGr) keep(gSmallFirm1 `controls' ) ///
	addtext(REG, OLS, YEAR, YES, COUNTY FE, YES, YRS, 2003-2017)

eststo: areg gsmall_dep1 gSmallFirm1 `controls' i.year if `years', ///
	vce(cluster cluster3) absorb(geography)
outreg2 using "$LocalData\Tables\BartikRegTable_1", tex append ///
	ctitle(SmDepGr) keep(gSmallFirm1 `controls' ) ///
	addtext(REG, OLS, YEAR, YES, COUNTY FE, YES, YRS, 2003-2017)

eststo: areg gsmall_dep1 gLargeFirm1 i.year `controls' if `years', cluster(cluster3) absorb(geography)
outreg2 using "$LocalData\Tables\BartikRegTable_1", tex append ///
	ctitle(SmDepGr) keep(gLargeFirm1 `controls' ) ///
	addtext(REG, OLS, YEAR, YES, COUNTY FE, YES, YRS, 2003-2017)

eststo: areg gsmall_dep1 gLargeFirm1 i.year if `years',  ///
	vce(cluster cluster3) absorb(geography)
outreg2 using "$LocalData\Tables\BartikRegTable_1", tex append ///
	ctitle(SmDepGr) keep(gLargeFirm1 `controls' ) ///
	addtext(REG, OLS, YEAR, YES, COUNTY FE, YES, YRS, 2003-2017)

eststo: areg gsmall_dep1 gSmallFirm1 gLargeFirm1 i.year if `years', ///
	vce(cluster cluster3) absorb(geography)
outreg2 using "$LocalData\Tables\BartikRegTable_1", tex append ///
	ctitle(SmDepGr) keep(gSmallFirm1 gLargeFirm1 `controls' ) ///
	addtext(REG, OLS, YEAR, YES, COUNTY FE, YES, YRS, 2002-2017)

eststo: areg gsmall_dep1 gSmallFirm1 gLargeFirm1 `controls' i.year if `years', ///
	vce(cluster cluster3) absorb(geography)
outreg2 using "$LocalData\Tables\BartikRegTable_1", tex append ///
	ctitle(SmDepGr) keep(gSmallFirm1 gLargeFirm1 `controls' ) ///
	addtext(REG, OLS, YEAR, YES, COUNTY FE, YES, YRS, 2002-2017)

noi display "Finished running simple regressions."
*noi etime
noi display " "
 
